home *** CD-ROM | disk | FTP | other *** search
- {$L TestMenus/Rsrc }
-
- program TestMenus;
-
- uses
- Macintf, StdPoll, StdMenu, IconMenu;
-
- const
- { Menu IDs }
- AppleMenuID = 256;
- AboutAlertID = 1000;
- FileMenuID = 257;
- EditMenuID = 258;
- CktMenuID = 259; { not a resource id }
- FirstCktIcon = 500;
- NumCktIcons = 7;
- IconsWide = 3;
- BfSpace = 3;
-
- var
- { Instances of Menu Handlers }
- AppleMenu : AppleMenuHdlr;
- FileMenu : StdFileMenuHdlr;
- EditMenu : StdEditMenuHdlr;
- CktMenu : IconMenuHdlr;
-
- { Event polling variables }
- TheEvent : EventRecord;
- EventIsForMe : Boolean;
-
-
- {
- | DoMenuChoice - do a menu selection
- }
- procedure DoMenuChoice (MenuCode : LongInt);
- begin
- case HiWord(MenuCode) of
- AppleMenuID : AppleMenu.Choose (LoWord(MenuCode));
- FileMenuID : FileMenu.Choose (LoWord(MenuCode));
- EditMenuID : EditMenu.Choose (LoWord(MenuCode));
- CktMenuID : CktMenu.Choose (LoWord(MenuCode)) end;
- HiliteMenu (0) end;
-
- {
- | PollEvent - check the event queue and dispatch event, if any
- }
- procedure PollEvent;
- var
- TempWindow : WindowPtr;
- begin
- EventIsForMe := GetNextEvent(everyEvent,TheEvent);
- if EventIsForMe
- then case TheEvent.what of
- mouseDown : case FindWindow (TheEvent.where,TempWindow) of
- inMenuBar : DoMenuChoice(MenuSelect(TheEvent.where));
- inSysWindow : SystemClick (TheEvent, TempWindow);
- otherwise { ignore } end;
- keyDown : if BitAnd(TheEvent.modifiers,CmdKey) <> 0
- then DoMenuChoice(MenuKey(
- CHR(BitAnd(TheEvent.message,CharCodeMask))));
- otherwise { ignore } end end;
-
-
- {
- | InitApplication
- }
- procedure InitApplication;
- begin
- Done := False;
-
- { Create the menus }
- New (AppleMenu);
- AppleMenu.Setup (AboutAlertID);
- AppleMenu.Create (AppleMenuID);
-
- New (FileMenu);
- FileMenu.Create (FileMenuID);
-
- New (EditMenu);
- EditMenu.Create (EditMenuID);
-
- New (CktMenu);
- CktMenu.Setup (FirstCktIcon, NumCktIcons, IconsWide,
- BfSpace, 'Model');
- CktMenu.Create (CktMenuID);
-
- DrawMenuBar;
-
- InitCursor end;
-
- {
- | Main
- }
- begin
- InitTheMac;
- InitApplication;
- repeat
- SystemTask;
- PollEvent;
- until done end.